package com.originalpoint.origin_server.controller;


import com.originalpoint.origin_server.empty.Result;
import com.originalpoint.origin_server.pojo.Admin;
import com.originalpoint.origin_server.service.AdminService;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

;

/**
 *@作者:lhj
 *Controller接口
 *@Date:2023/07/02
*/
@CrossOrigin
@RestController
@RequestMapping("/AdminURL")
public class AdminController {


	@Autowired
	private AdminService adminservice;


	/**
	根据AdminId查询
	*/
	@ApiOperation(value  = "通过Id查询管理员信息")
	@GetMapping("/selectByAdminId/{adminId}")
	public Result selectByAdminId(@PathVariable(value = "adminId") Integer adminId){
		return Result.buildSuccess(adminservice.selectByAdminId(adminId));
	}


	/**
	根据AdminId更新
	*/
	@ApiOperation(value  = "根据AdminId更新管理员信息")
	@PostMapping("/updateByAdminId")
	public Result updateByAdminId(@RequestBody Admin demo){
		return Result.buildSuccess(adminservice.updateByAdminId( demo));
	}



	/**
	根据AdminId删除
	*/
	@ApiOperation(value  = "根据AdminId删除管理员信息")
	@GetMapping("/deleteByAdminId/{adminId}")
	public Result deleteByAdminId(@PathVariable(value = "adminId") Integer adminId){
		return Result.buildSuccess(adminservice.deleteByAdminId(adminId));
	}





	/**
	 insert:(插入)
	*/
	@ApiOperation(value  = "往管理员表插入管理员信息")
	@PostMapping("/insert")
	public Result insert(@RequestBody Admin demo){
		Result.buildSuccess(adminservice.insert(demo));
		return Result.buildSuccess(demo);
	}



	/**
	 insertOrUpdate(插入或更新(根据主键或唯一索引更新，主键和唯一索引不会改变))
	*/
	@ApiOperation(value  = "插入或更新(根据主键或唯一索引更新，主键和唯一索引不会改变)管理员表")
	@PostMapping("/insertOrUpdate")
	public Result insertOrUpdate(@RequestBody Admin demo){
		return Result.buildSuccess(adminservice.insertOrUpdate(demo));
	}



	/**
	 insertBath:(批量插入)
	*/
	@ApiOperation(value  = "批量插入管理员表")
	@PostMapping("/insertBatch")
	public Result insertBatch(@RequestBody List<Admin> list){
		return Result.buildSuccess(adminservice.insertBatch(list));
	}



	/**
	 insertOrUpdateBatch:(批量插入或更新)
	*/
	@ApiOperation(value  = "批量插入或更新管理员信息")
	@PostMapping("/insertOrUpdateBatch")
	public Result insertOrUpdateBatch(@RequestBody List<Admin> list){
		return Result.buildSuccess(adminservice.insertOrUpdateBatch(list));
	}



	/**
	 selectList:(根据参数查询集合)
	*/
	@ApiOperation(value  = "根据参数查询集合")
	@PostMapping("/selectList")
	public Result selectList(@RequestBody Map<String,Object> param){
		return Result.buildSuccess(adminservice.selectList(param),adminservice.selectCount(param));
	}



	/**
	 selectCount:(根据集合查询数量)
	*/
	@ApiOperation(value  = "根据集合查询数量")
	@PostMapping("/selectCount")
	public Result selectCount(@RequestBody Map<String,Object> param){
		return Result.buildSuccess(adminservice.selectCount(param));
	}



}